package com.music.mysongs.fragment.main

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.music.mysongs.R
import com.music.mysongs.activity.OptionActivity
import com.music.mysongs.helper.*
import kotlinx.android.synthetic.main.fragment_mine.*

class MineFragment : Fragment(), View.OnClickListener {
    private val mTAG = "MineFragment"

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val hello = myActReadStringSPF(this.activity, "spfUserName") + " , " + getDateNode() + " ~ "
        editHelloTime_mine.setText(hello)
        //Glide.with(this).load("").into(imgHead_mine)
        editAccount_mine.setOnClickListener(this)
        editCollection_mine.setOnClickListener(this)
        editTodayHistory_mine.setOnClickListener(this)
        editChangeTheme_mine.setOnClickListener(this)
        editLogout_mine.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.editAccount_mine -> {
                Intent(activity, OptionActivity::class.java).apply {
                    putExtra("_option", "op_account")
                    startActivity(this)
                }
            }
            R.id.editCollection_mine -> {
                Intent(activity, OptionActivity::class.java).apply {
                    putExtra("_option", "op_collection")
                    startActivity(this)
                }
            }
            R.id.editTodayHistory_mine -> {
                Intent(activity, OptionActivity::class.java).apply {
                    putExtra("_option", "op_history")
                    startActivity(this)
                }
            }
            R.id.editChangeTheme_mine -> {
                val intentTheme = Intent("com.music.mysongs.THEME")
                intentTheme.setPackage(requireContext().packageName)
                requireContext().sendBroadcast(intentTheme)
            }
            R.id.editLogout_mine -> {//退出登录
                val intentOff = Intent("com.music.mysongs.OFFLINE")
                intentOff.setPackage(requireContext().packageName)
                requireContext().sendBroadcast(intentOff)
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        super.onCreateView(inflater, container, savedInstanceState)
        return inflater.inflate(R.layout.fragment_mine, container, false)
    }
}